﻿Imports System.Data.Sql

Public Class ConnectionString

    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        Me.Close()

    End Sub

    Private Sub ConnectionString_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CenterToScreen()
        Me.Cursor = Cursors.WaitCursor

        Dim dataTable As DataTable = SqlDataSourceEnumerator.Instance.GetDataSources()
        DataGridView1.DataSource = dataTable
        Me.Cursor = Cursors.Default

    End Sub

    Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        Dim strServer As String = DataGridView1.Rows(e.RowIndex).Cells(0).Value
        Dim strInstance As String = ""

        Try
            If Not String.IsNullOrEmpty(DataGridView1.Rows(e.RowIndex).Cells(1).Value) Then
                strInstance = DataGridView1.Rows(e.RowIndex).Cells(1).Value
            End If
        Catch ex As Exception

        End Try

        Dim cs As String
        If strInstance.Length > 0 Then
            cs = "Data Source=" & strServer & "\" & strInstance & ";Initial Catalog=myDataBase;user id=YourUserId;Password=YourPassword;"
        Else
            cs = "Data Source=" & strServer & ";Initial Catalog=myDataBase;user id=YourUserId;Password=YourPassword;"
        End If
        txtCN.Text = cs

    End Sub

    Private Sub cmdCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCopy.Click
        Clipboard.SetDataObject(txtCN.Text, True)
        MessageBox.Show("Connection String is copied to clipboard!!!")
    End Sub
End Class
